package cn.bdqn.mapper;

import cn.bdqn.model.Person;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.StatementType;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author gurilla
 * @create 2019-08-11 10:54
 */
public interface PersonMapper {
    @Insert("insert into t_person1 (name, sex, birthday) values (#{name}, #{sex}, #{birthday})")
    void insert(@Param(value = "name") String name, @Param(value = "sex")Integer sex, @Param(value = "birthday")Date birthday);

    @Select("select * from t_person")
    List<Person> getall();

    @Insert("<script>INSERT INTO t_person1(name,sex,birthday) VALUES\n" +
            "<foreach collection =\"list\" item=\"person\" separator =\",\">\n" +
            " (#{person.name}, #{person.sex}, #{person.birthday})\n" +
            "</foreach></script>")
    void insertBatch(List<Person> persons);

    @Delete("delete from person1")
    void delete();

    @Select("call p_check(#{reuslt,mode=OUT,jdbcType=INTEGER})")
    @Options(statementType = StatementType.CALLABLE)
    void check(Map<String,Object> map);

    @Select("select * from t_person1")
    List<Person> geterror();
}
